//
//  BaseViewCtr.swift
//  SwiftStory
//
//  Created by ZxjMacBookPro on 2020/4/16.
//  Copyright © 2020 ZxjMacBookPro. All rights reserved.
//

import UIKit

class BaseViewCtr: UIViewController {
    ///访客试图
    var visitorView : VisitorView?
    ///登录状态
    var isLogin = UserAcount.isLogin()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    
    override func loadView() {
        isLogin ? super.loadView() : setUpVisitorView()
        
        //        let otherView = VisitorView.visitorView()
        //        self.view = otherView
        //        let otherView = UIView()
        //        otherView.backgroundColor = UIColor.orange
        //报错写法
//        self.view.backgroundColor = UIColor.orange
    }

    private func setUpVisitorView(){
        visitorView = VisitorView.visitorView()
        self.view = visitorView
        visitorView?.loginBtn.addTarget(self, action: #selector(loginBtnClick), for: .touchUpInside)
        visitorView?.registerBtn.addTarget(self, action: #selector(registerBtnClick), for: .touchUpInside)
    }
    
    @objc private func loginBtnClick(btn: UIButton){
        let vc = OAuthViewCtr()
        let nav = UINavigationController(rootViewController: vc)
        present(nav, animated: true, completion: nil)
//        vc.hidesBottomBarWhenPushed = true
//        navigationController?.pushViewController(vc, animated: true)
    }
    
    @objc private func registerBtnClick(btn: UIButton){
        NSLog(message: "")
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
